package com.xiaoxu.intranetweb.mybatisplusSzappdb.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.TFactoryProcessInfo;

import com.xiaoxu.intranetweb.mybatisplusSzappdb.mapper.TFactoryProcessInfoMapper;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.service.ITFactoryProcessInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxu.intranetweb.util.SzResult;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoxu
 * @since 2024-08-26
 */
@Service
public class TFactoryProcessInfoServiceImpl extends ServiceImpl<TFactoryProcessInfoMapper, TFactoryProcessInfo> implements ITFactoryProcessInfoService {
    @Override
    public SzResult addFactoryProcessInfo(TFactoryProcessInfo factoryProcessInfo) {
        QueryWrapper<TFactoryProcessInfo> factoryProcessInfoQueryWrapper = new QueryWrapper<>();
        factoryProcessInfoQueryWrapper.eq("CPY_ID",factoryProcessInfo.getCpyId());
        factoryProcessInfoQueryWrapper.eq("PDT_CLASS_NAME",factoryProcessInfo.getPdtClassName());
        if (getOne(factoryProcessInfoQueryWrapper) != null) {
            return SzResult.error("该公司或分组已重复");
        }
        return SzResult.success(save(factoryProcessInfo));
    }

    @Override
    public SzResult updateFactoryProcessInfo(TFactoryProcessInfo factoryProcessInfo) {

        TFactoryProcessInfo processInfo = getById(factoryProcessInfo.getId());
        if (processInfo.getCpyId().equals(factoryProcessInfo.getCpyId()) && processInfo.getPdtClassName().equals(factoryProcessInfo.getPdtClassName())) {
            return SzResult.success(updateById(factoryProcessInfo));
        }
        QueryWrapper<TFactoryProcessInfo> factoryProcessInfoQueryWrapper = new QueryWrapper<>();
        factoryProcessInfoQueryWrapper.eq("CPY_ID",factoryProcessInfo.getCpyId());
        factoryProcessInfoQueryWrapper.eq("PDT_CLASS_NAME",factoryProcessInfo.getPdtClassName());
        if (getOne(factoryProcessInfoQueryWrapper) != null) {
            return SzResult.error("该公司或分组已重复");
        }
        return SzResult.success(updateById(factoryProcessInfo));
    }
}
